package com.eliza.music.compoment.music

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.eliza.music.model.entity.BasicInfo
import com.eliza.music.model.entity.Category
import com.eliza.music.model.tmp.ListDataCategory
import com.eliza.music.model.tmp.PlaylistList
import com.eliza.music.ui.theme.PaddingSize


@Preview
@Composable
private fun CategoryViewShow() {
    CategoryView.ItemList(Category("as", 1, PlaylistList))
}

@Preview
@Composable
private fun CategoryListShow() {
    CategoryView.CategoryList("title", ListDataCategory)

}

object CategoryView {
    @Composable
    fun <T : BasicInfo> ItemList(data: Category<T>, modifier: Modifier = Modifier) {
        Column(
            modifier = Modifier
                .then(modifier)
                .verticalScroll(rememberScrollState())
        ) {
            data.children.forEach {
                SongView.ItemInList(
                    it, modifier = Modifier.padding(
                        PaddingSize.Normal.size
                    )
                )
            }
        }
    }

    @Composable
    fun <T : BasicInfo> CategoryList(
        title: String, data: List<Category<T>>, modifier: Modifier = Modifier
    ) {
        Column(modifier.padding(0.dp, PaddingSize.Normal.size)) {
            Text(
                title,
                fontWeight = FontWeight.Bold,
                modifier = modifier.padding(PaddingSize.Normal.size)
            )
            data.forEach {
                ItemList(it)

            }
        }
    }

}
